package net.realsee.service.wcs.data.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.realsee.common.utils.StringUtils;
import net.realsee.domain.wcs.data.WcsLiteralDictTranslation;
import net.realsee.domain.wcs.data.bo.WcsLiteralDictTranslationBo;
import net.realsee.domain.wcs.data.vo.WcsLiteralDictTranslationVo;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.mapper.wcs.data.WcsLiteralDictTranslationMapper;
import net.realsee.service.wcs.data.IWcsLiteralDictTranslationService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 词典翻译Service业务层处理
 *
 * @author realsee
 * @date 2023-08-11
 */
@RequiredArgsConstructor
@Service
public class WcsLiteralDictTranslationServiceImpl extends ServiceImpl<WcsLiteralDictTranslationMapper, WcsLiteralDictTranslation> implements IWcsLiteralDictTranslationService {

    private final WcsLiteralDictTranslationMapper baseMapper;

    /**
     * 查询词典翻译
     */
    @Override
    public WcsLiteralDictTranslationVo selectVoById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询词典翻译列表
     */
    @Override
    public TableDataInfo<WcsLiteralDictTranslationVo> selectVoPage(WcsLiteralDictTranslationBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<WcsLiteralDictTranslation> lqw = buildVoQueryWrapper(bo);
        Page<WcsLiteralDictTranslationVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询词典翻译列表
     */
    @Override
    public List<WcsLiteralDictTranslationVo> selectVoList(WcsLiteralDictTranslationBo bo) {
        LambdaQueryWrapper<WcsLiteralDictTranslation> lqw = buildVoQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<WcsLiteralDictTranslation> buildVoQueryWrapper(WcsLiteralDictTranslationBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<WcsLiteralDictTranslation> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, WcsLiteralDictTranslation::getId, bo.getId());
        lqw.eq(bo.getLiteralDictionaryId() != null, WcsLiteralDictTranslation::getLiteralDictionaryId, bo.getLiteralDictionaryId());
        lqw.eq(bo.getLanguageId() != null, WcsLiteralDictTranslation::getLanguageId, bo.getLanguageId());
        lqw.eq(StringUtils.isNotBlank(bo.getVersion()), WcsLiteralDictTranslation::getVersion, bo.getVersion());
        lqw.eq(bo.getHasChanges() != null, WcsLiteralDictTranslation::getHasChanges, bo.getHasChanges());
        lqw.eq(StringUtils.isNotBlank(bo.getMicro()), WcsLiteralDictTranslation::getMicro, bo.getMicro());
        lqw.eq(StringUtils.isNotBlank(bo.getMini()), WcsLiteralDictTranslation::getMini, bo.getMini());
        lqw.eq(StringUtils.isNotBlank(bo.getMedium()), WcsLiteralDictTranslation::getMedium, bo.getMedium());
        lqw.eq(StringUtils.isNotBlank(bo.getExtended()), WcsLiteralDictTranslation::getExtended, bo.getExtended());
        lqw.eq(StringUtils.isNotBlank(bo.getMicroAudioUrl()), WcsLiteralDictTranslation::getMicroAudioUrl, bo.getMicroAudioUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getShortAudioUrl()), WcsLiteralDictTranslation::getShortAudioUrl, bo.getShortAudioUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getMediumAudioUrl()), WcsLiteralDictTranslation::getMediumAudioUrl, bo.getMediumAudioUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getLongAudioUrl()), WcsLiteralDictTranslation::getLongAudioUrl, bo.getLongAudioUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getSmallIconUrl()), WcsLiteralDictTranslation::getSmallIconUrl, bo.getSmallIconUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getMediumIconUrl()), WcsLiteralDictTranslation::getMediumIconUrl, bo.getMediumIconUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getLargeIconUrl()), WcsLiteralDictTranslation::getLargeIconUrl, bo.getLargeIconUrl());
        lqw.eq(StringUtils.isNotBlank(bo.getFuid()), WcsLiteralDictTranslation::getFuid, bo.getFuid());
        lqw.eq(bo.getTextId() != null, WcsLiteralDictTranslation::getTextId, bo.getTextId());
        lqw.eq(bo.getRefrenceId() != null, WcsLiteralDictTranslation::getRefrenceId, bo.getRefrenceId());
        lqw.eq(bo.getUnitId() != null, WcsLiteralDictTranslation::getUnitId, bo.getUnitId());
        lqw.eq(bo.getDelFlag() != null, WcsLiteralDictTranslation::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), WcsLiteralDictTranslation::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, WcsLiteralDictTranslation::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), WcsLiteralDictTranslation::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, WcsLiteralDictTranslation::getUpdateTime, bo.getUpdateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getDeleteBy()), WcsLiteralDictTranslation::getDeleteBy, bo.getDeleteBy());
        lqw.eq(bo.getDeleteTime() != null, WcsLiteralDictTranslation::getDeleteTime, bo.getDeleteTime());
        lqw.eq(bo.getRowVersionStamp() != null, WcsLiteralDictTranslation::getRowVersionStamp, bo.getRowVersionStamp());
        return lqw;
    }

    /**
     * 新增词典翻译
     */
    @Override
    public Boolean insertByBo(WcsLiteralDictTranslationBo bo) {
        WcsLiteralDictTranslation add = BeanUtil.toBean(bo, WcsLiteralDictTranslation.class);
        return this.save(add);
    }

    /**
     * 修改词典翻译
     */
    @Override
    public Boolean updateByBo(WcsLiteralDictTranslationBo bo) {
        WcsLiteralDictTranslation update = BeanUtil.toBean(bo, WcsLiteralDictTranslation.class);
        return this.updateById(update);
    }

    /**
     * 批量删除词典翻译
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids) {
        return this.removeBatchByIds(ids);
    }
}
